from django.http import JsonResponse


class HttpCode():
    ok = 200
    paramserror = 400
    unauth = 401
    methoderror = 405
    servererror = 500


def ok(code=HttpCode.ok, message='', data=None, kwargs=None):
    json_dict = {'code': code, 'message': message, data: data}
    if kwargs and isinstance(kwargs, dict) and kwargs.keys():
        json_dict.update(kwargs)
    return JsonResponse(json_dict, json_dumps_params={'ensure_ascii': False})


def params_error(message='', data=None):
    return ok(HttpCode.paramserror, message, data)


def unauth_error(message='', data=None):
    return ok(HttpCode.unauth, message, data)


def method_error(message='', data=None):
    return ok(HttpCode.methoderror, message, data)


def server_error(message='', data=None):
    return ok(HttpCode.servererror, message, data)
